//过滤ajax数据，使其用表单形式传输
export function changeDataType(json) {

	var a = Object.keys(json).map(
		function(k) {
			return encodeURIComponent(k) + '=' + encodeURIComponent(json[k])
		}
	).join('&');

	return a;
	
}

//深拷贝一个Object
export function cloneObj(obj) {
	if(obj === null) {
		return '';
	}
	if(typeof obj !== 'object') {
		return obj;
	}
	var s = {};
	if(obj.constructor === Array) {
		s = [];
	}
	for(var i in obj) {
		s[i] = cloneObj(obj[i]);
	}
	return s;
}

//过滤时间格式
export function timeFilter(time, format) {
	var o = {
		'M+': time.getMonth() + 1, //month 
		'd+': time.getDate(), //day 
		'H+': time.getHours(), //hour 
		'm+': time.getMinutes(), //minute 
		's+': time.getSeconds(), //second 
		'q+': Math.floor((time.getMonth() + 3) / 3), //quarter 
		'S': time.getMilliseconds() //millisecond 
	}

	if(/(y+)/.test(format)) {
		format = format.replace(RegExp.$1, (time.getFullYear() + '').substr(4 - RegExp.$1.length));
	}

	for(var k in o) {
		if(new RegExp('(' + k + ')').test(format)) {
			format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length));
		}
	}
	return format;
}

//获取随机数，无小数点
export function getRandomInt(min, max) {
	return Math.floor(Math.random() * (max - min + 1) + min);
}